var cookie = {
	//获取cookie
	//cookie.get("name");
    kJget: function (name){
        var cookieName = encodeURIComponent(name) + "=",
            cookieStart = document.cookie.indexOf(cookieName),
            cookieValue = null,
            cookieEnd;
        if (cookieStart > -1){
            cookieEnd = document.cookie.indexOf(";", cookieStart);
            if (cookieEnd == -1){
                cookieEnd = document.cookie.length;
            }
            cookieValue = decodeURIComponent(document.cookie.substring(cookieStart + cookieName.length, cookieEnd));
        } 

        return cookieValue;
    },
    // 设置cookie
    kJset: function (name, value, expires, path, domain, secure) {
        var cookieText = encodeURIComponent(name) + "=" + encodeURIComponent(value);
    
        if (expires instanceof Date) {
            cookieText += "; expires=" + expires.toGMTString();
        }
        if (path) {
            cookieText += "; path=" + path;
        }
        if (domain) {
            cookieText += "; domain=" + domain;
        }
        if (secure) {
            cookieText += "; secure";
        }
    
        document.cookie = cookieText;
        //document.cookie = "name=value;expires=[GMTStr];path=;domain=;secure;"
    },
    // cookie append每次提交的cookie后面在拼接一个串新的cookie，单个cookie设置
    kJappend:function(obj){
        //通过数组转字符串，添加在转JSON串形式

    },
    // 删除cookie
    kJdelete: function (name, path, domain, secure){
        this.kJset(name, "", new Date(0), path, domain, secure);
    },
    // 格式日期,设置过期时间,转换为GMT格式日期
    kJformatData:function(num){
        var date = new Date();
        date.setDate(date.getDate() + num);
        return date;
    },
    // 清楚浏览器中全部cookie
    kJClearAll:function(path){
    	var keys=document.cookie.match(/[^ =;]+(?=\=)/g); 
		if (keys) { 
			for (var i = keys.length;i--;) {
				document.cookie=keys[i]+'=0;expires=' + new Date(0).toUTCString() +';path=' + path;
			}
		} 
    }
};

/**
 * 详解：
 * cookie 完整格式为：name=value;[expires=date];[path=path];[domain=somewhere.com];[secure] 
 * name
 * value
 * 有效时间expires
 * 路径
 * 作用域
 * 安全标志 https
 *
 * 核心语法
 * document.cookie
 *
 * 常用使用方法：
 * 
 * cookie.kJget("name");
 *
 * cookie.kJset(name, value, expires, path, domain, secure);
 * 例子
 * cookie.kJset("name","value");
 * cookie.kJset("name","value",cookie.kJformatData(6))
 * cookie.kJset("name","value",cookie.kJformatData(6),'/')
 * 
 */